package ace.module.stock.core.impl.dao.aggregate.helper;

import ace.cmp.util.AceNumberUtils;
import ace.cmp.util.AceStreamUtils;
import ace.module.stock.core.impl.dao.entity.WmsStock;
import java.util.List;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * 库存 aggregate.
 *
 * @author Caspar
 */
@AllArgsConstructor
@Component
public class WmsStockAggregateHelper {

  public WmsStock findById(List<WmsStock> wmsStocks, Long id) {
    return AceStreamUtils.ofNullable(wmsStocks)
        .filter(p -> id.equals(p.getId()))
        .findFirst()
        .orElse(null);
  }


  public WmsStock findByObjectIdAndObjectType(List<WmsStock> wmsStocks, Long objectId, Integer objectType) {
    return AceStreamUtils.ofNullable(wmsStocks)
        .filter(p -> AceNumberUtils.isEquals(objectId, p.getId()))
        .filter(p -> AceNumberUtils.isEquals(objectType, p.getObjectType()))
        .findFirst()
        .orElse(null);
  }
}